package o;

import com.google.android.exoplayer2.Format;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import okhttp3.internal.connection.RealConnection;

final class afo extends afq {
    private static final int ˋ = anr.ᐝ("Opus");
    private static final byte[] ॱ = new byte[]{(byte) 79, (byte) 112, (byte) 117, (byte) 115, (byte) 72, (byte) 101, (byte) 97, (byte) 100};
    private boolean ˊ;

    afo() {
    }

    public static boolean ˋ(anc o_anc) {
        if (o_anc.ˊ() < ॱ.length) {
            return false;
        }
        byte[] bArr = new byte[ॱ.length];
        o_anc.ˎ(bArr, 0, ॱ.length);
        return Arrays.equals(bArr, ॱ);
    }

    protected void ˏ(boolean z) {
        super.ˏ(z);
        if (z) {
            this.ˊ = false;
        }
    }

    protected long ˏ(anc o_anc) {
        return ˎ(ˎ(o_anc.ˏ));
    }

    protected boolean ˎ(anc o_anc, long j, c cVar) {
        if (this.ˊ) {
            boolean z = o_anc.ॱᐝ() == ˋ;
            o_anc.ˋ(0);
            return z;
        }
        Object copyOf = Arrays.copyOf(o_anc.ˏ, o_anc.ॱ());
        int i = copyOf[9] & 255;
        int i2 = ((copyOf[11] & 255) << 8) | (copyOf[10] & 255);
        List arrayList = new ArrayList(3);
        arrayList.add(copyOf);
        ॱ(arrayList, i2);
        ॱ(arrayList, 3840);
        cVar.ˏ = Format.ˎ(null, "audio/opus", null, -1, -1, i, 48000, arrayList, null, 0, null);
        this.ˊ = true;
        return true;
    }

    private void ॱ(List<byte[]> list, int i) {
        list.add(ByteBuffer.allocate(8).order(ByteOrder.nativeOrder()).putLong((((long) i) * RealConnection.MAX_RESERVE_DURATION_NS) / 48000).array());
    }

    private long ˎ(byte[] bArr) {
        int i;
        int i2 = bArr[0] & 255;
        switch (i2 & 3) {
            case 0:
                i = 1;
                break;
            case 1:
            case 2:
                i = 2;
                break;
            default:
                i = bArr[1] & 63;
                break;
        }
        int i3 = i2 >> 3;
        i2 = i3 & 3;
        if (i3 >= 16) {
            i3 = 2500 << i2;
        } else if (i3 >= 12) {
            i3 = 10000 << (i2 & 1);
        } else if (i2 == 3) {
            i3 = 60000;
        } else {
            i3 = 10000 << i2;
        }
        return ((long) i3) * ((long) i);
    }
}
